<?php
require_once "common.php";
$aid=$_GET[aid];
//var_dump($aid);
if($aid!=''){
	@$article=new article($aid);
	//使用函数返回文章数组
	$essay=$article->returnArticle();
	//echo $essay;
	$pid=$essay[pid];
	@$part=new part($pid,'','');
	$partName=$part->selectPart();
	//var_dump($partName);
	//print_r($essay);
	//var_dump($essay[pid]);
	}
?>
<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Default Examples</title>
		<style>
			form {
				margin: 0;
			}
			textarea {
				display: block;
			}
		</style>
		<script charset="utf-8" src="./editor/kindeditor-min.js"></script>
		<script charset="utf-8" src="./editor/lang/zh_CN.js"></script>
		<script>
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					allowFileManager : true
				});
				K('input[name=getHtml]').click(function(e) {
					alert(editor.html());
				});
				K('input[name=isEmpty]').click(function(e) {
					alert(editor.isEmpty());
				});
				K('input[name=getText]').click(function(e) {
					alert(editor.text());
				});
				K('input[name=selectedHtml]').click(function(e) {
					alert(editor.selectedHtml());
				});
				K('input[name=setHtml]').click(function(e) {
					editor.html('<h3>Hello KindEditor</h3>');
				});
				K('input[name=setText]').click(function(e) {
					editor.text('<h3>Hello KindEditor</h3>');
				});
				K('input[name=insertHtml]').click(function(e) {
					editor.insertHtml('<strong>插入HTML</strong>');
				});
				K('input[name=appendHtml]').click(function(e) {
					editor.appendHtml('<strong>添加HTML</strong>');
				});
				K('input[name=clear]').click(function(e) {
					editor.html('');
				});
			});
		</script>
	</head>
	<body>
		<form action="./article_edit.php" method="post">
			<p>标&nbsp&nbsp题：<input type="text" name="title" value="<?php echo $essay[title]; ?>" size=30/></p>
			<p>关键字：<input type="text" name="keyword" value="<?php echo $essay[keyword]; ?>" size=30/></p>
			<p style="margin-top:0px;font-size:14px;font-family:Simsun;">文章简介：<textarea name="describe" cols="97" rows="3" type="width:800px;height:100px;"><?php echo $essay[describe]; ?></textarea></p>
			<p>栏&nbsp&nbsp目：<select name="partList">
					<option selected="selected"><?php echo $partName[part]; ?></opption>
				</select></p>
				<input type="hidden" name="aid" value="<?php echo $essay[aid];?>" />
			<textarea name="content" style="width:800px;height:400px;visibility:hidden;"><?php echo $essay[content]; ?></textarea>
            <p>
            热门推荐<input type="checkbox" name="hot" value="1" <?php if($essay[recommend]==1){echo "checked";} ?>/>
            首页幻灯<input type="checkbox" name="slide_show" value="1" <?php if($essay[slide_show]==1){echo "checked"; }?> />
            </p>
			<input type="submit" name="submit" value="提交" />
		</form>
	</body>
</html>
<?php
	$array=array();
	$aid=$_POST[aid];
	if($aid!=''){
		$array[title]=$_POST[title];
		$array[keyword]=$_POST[keyword];
		$array[content]=$_POST[content];
		$array[describe]=$_POST[describe];
		$array[recommend]=$_POST[hot];
		$array[slide_show]=$_POST[slide_show];
		@$article=new article($aid);
		$res=$article->editArticle($array);
		//var_dump($res);
		if($res){
			$redirector=new redirector('./article_list.php?pid='.$partName[pid],3,'文章修改成功');
			$redirector->redirect();
		}else{
			$redirector=new redirector('./article_list.php?pid='.$partName[pid],3,'文章修改失败');
			$redirector->redirect();
            }
	}
	
?>
